// 房间信息表
module.exports = app => {
  const { INTEGER, STRING, DATE } = app.Sequelize;
  const HotelRoom = app.model.define('hotel_room', {
    id: { type: INTEGER, primaryKey: true, autoIncrement: true },
    room_id: { type: INTEGER, unique: true }, // 房间编号
    title: STRING, // 房间标题
    room_equ: { type: STRING, comment: '房配套设施:wifi，洗衣机' },
    room_number: INTEGER, // 客房可住人数
    room_price: INTEGER, // 价格
    room_type: STRING, // 房间类型
    room_eat: { type: STRING, defaultValue: '无早餐' }, // 是否有早餐
    room_state: { type: STRING, defaultValue: '空房' }, // 房间状态 ，空房或者一住宿
    room_pic: STRING, // 房间图片
    created_at: { type: DATE, defaultValue: new Date() }, // 创建时间

  });
  HotelRoom.associate = function() {
    app.model.HotelRoom.hasOne(app.model.Reservation, {
      foreignKey: 'room_id',
      sourceKey: 'room_id',
      // as: 'hotel',
    });
    app.model.HotelRoom.belongsTo(app.model.Hotel, {
      foreignKey: 'hotel_id',
      targetKey: 'hotel_id',
      // as: 'hotel',
    }
    );
  };
  return HotelRoom;
};
